package com.qidianit.mes.sys.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.Supplier;
import com.qidianit.mes.sys.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 供应商管理控制器
 */
@RestController
@RequestMapping("/supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    /**
     * 批量删除供应商
     */
    @DeleteMapping("/batchDelete")
    public Result batchDelete(Long[] id) {
        return supplierService.batchDelete(id);
    }

    /**
     * 根据ID删除供应商
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Long id) {
        return supplierService.deleteById(id);
    }

    /**
     * 更新供应商信息
     */
    @PutMapping("/update")
    public Result update(@RequestBody Supplier supplier) {
        return supplierService.updateById(supplier);
    }

    /**
     * 新增供应商
     */
    @PostMapping("/add")
    public Result save(@RequestBody Supplier supplier) {
        return supplierService.saveSupplier(supplier);
    }

    /**
     * 根据编码查询供应商
     */
    @GetMapping("/code/{code}")
    public Result<Supplier> getByCode(@PathVariable("code") String code) {
        return supplierService.selectByCode(code);
    }

    /**
     * 分页查询供应商列表
     */
    @GetMapping("/page")
    public Result<PageInfo<Supplier>> list(
            Supplier supplier, 
            @RequestParam(defaultValue = "1") int pageNum, 
            @RequestParam(defaultValue = "10") int pageSize) {
        return supplierService.selectList(supplier, pageNum, pageSize);
    }
}
    